/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package espe.ccsoft.controllers;

import espe.ccsoft.controllers.utils.JsfUtil;
import espe.ccsoft.dao.PermisoRolDao;
import espe.ccsoft.models.PermisoRol;
import java.util.List;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class PermisoRolController {

    private PermisoRol permisorol;
    private PermisoRolDao permisoroldao;

    public PermisoRol getSelected() {
        if (permisorol == null) {
            permisorol = new PermisoRol();
        }

        return permisorol;
    }

    public PermisoRolDao getPermisoDao() {
        permisoroldao = new PermisoRolDao();
        return permisoroldao;
    }

    public void crearPermisos(List<Integer> id_rol, int id_permiso) throws Exception {
        try {
            for (Object idrol : id_rol) {
                PermisoRol permisorolTmp = new PermisoRol();

                permisorolTmp.setPermiso_rol(id_permiso, Integer.parseInt(idrol.toString()));
                getPermisoDao().insert(permisorolTmp);

            }
        } catch (Exception e) {
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("/PermisosLabels").getString("Error"));
        }
    }
    
    public void elminarPermisos(int id_permiso){
        try{
            getPermisoDao().delete(id_permiso);
        }catch (Exception e) {
            JsfUtil.addErrorMessage(ResourceBundle.getBundle("/PermisosLabels").getString("Error"));
        }
    }
}
